package com.yaozheng.vocationaltraining.adapter;

import org.json.JSONArray;
import org.json.JSONException;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.activity.BaseActivity;
import com.yaozheng.vocationaltraining.utils.JsonUtils;
import com.yaozheng.vocationaltraining.view.IntegralTypeListItemView;
import com.yaozheng.vocationaltraining.view.IntegralTypeListItemView_;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class IntegralTypeListAdapter extends BaseAdapter {
	/**
	 * activity
	 */
	private BaseActivity baseActivity;
	/**
	 * 数据
	 */
	private JSONArray dataList;

	public IntegralTypeListAdapter(BaseActivity baseActivity) {
		super();
		this.baseActivity = baseActivity;

		try {
			dataList = new JSONArray(
					baseActivity.getString(R.string.integralTypeJsonStr));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// JsonUtils.getJsonArray(baseActivity
		// .getString(R.string.integralTypeJsonStr));
	}

	@Override
	public int getCount() {
		if (dataList == null)
			return 0;
		return dataList.length();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		IntegralTypeListItemView integralTypeListItemView;
		if (convertView == null) {
			integralTypeListItemView = IntegralTypeListItemView_
					.build(baseActivity);
		} else {
			integralTypeListItemView = (IntegralTypeListItemView) convertView;
		}
		integralTypeListItemView.loadData(position,
				dataList.optJSONObject(position));
		return integralTypeListItemView;
	}

}
